package com.guojian.jdbc;

import javax.sql.DataSource;

import org.springframework.boot.autoconfigure.jdbc.JdbcProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import com.guojian.jdbc.sql.SqlParser;

@Configuration
public class JdbcTemplateXAutoConfiguration {

	@Bean
	@Primary
	public JdbcTemplateX jdbcTemplate(DataSource dataSource, JdbcProperties properties, SqlParser sqlParser) {
		JdbcTemplateX jdbcTemplate = new JdbcTemplateX(dataSource, sqlParser);
		JdbcProperties.Template template = properties.getTemplate();
		jdbcTemplate.setFetchSize(template.getFetchSize());
		jdbcTemplate.setMaxRows(template.getMaxRows());
		if (template.getQueryTimeout() != null) {
			jdbcTemplate.setQueryTimeout((int) template.getQueryTimeout().getSeconds());
		}
		return jdbcTemplate;
	}

	public static void main(String[] args) {

	}

}
